package com.cali.libcore.view.compose

import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.view.Gravity.CENTER_HORIZONTAL
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.cali.common.kt.defaultTextSize
import com.cali.libcore.R
import kotlinx.android.synthetic.main.include_vertical_two_tv.view.*

class VerticalTwoTextView(context: Context, val attrs: AttributeSet?, def: Int) : LinearLayout(context, attrs, def) {

    constructor(context: Context) : this(context, null, 0)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    init {
        orientation = VERTICAL
        //加载视图
        LayoutInflater.from(context).inflate(R.layout.include_vertical_two_tv, this)
        context.theme.obtainStyledAttributes(attrs, R.styleable.VerticalTwoTextView, 0, 0)?.apply {
            tvTop.text = getString(R.styleable.VerticalTwoTextView_tv_top_text)
            tvBottom.text = getString(R.styleable.VerticalTwoTextView_tv_bottom_text)
            val tvTopColor = getColor(R.styleable.VerticalTwoTextView_tv_top_text_color, 0)
            val tvBottomColor = getColor(R.styleable.VerticalTwoTextView_tv_bottom_text_color, 0)
            val tvTopSize = getDimensionPixelSize(R.styleable.VerticalTwoTextView_tv_top_text_size, context.defaultTextSize())
            val tvBottomSize = getDimensionPixelSize(R.styleable.VerticalTwoTextView_tv_bottom_text_size,context.defaultTextSize())
            tvTop.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTopSize.toFloat())
            tvBottom.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvBottomSize.toFloat())
            if(tvTopColor!=0) tvTop.setTextColor(tvTopColor)
            if(tvBottomColor!=0) tvBottom.setTextColor(tvBottomColor)
            recycle()
        }
    }

    fun setTopText(content:String) {
        tvTop.text = content
    }

    fun setBottomText(content: String) {
        tvBottom.text = content
    }
}